//package com.zny.sescore.shiro;
//
//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
//import com.palmdoctor.mb.base.constant.AuditStatusEnum2;
//import com.palmdoctor.mb.base.constant.UserTypeEnum;
//import com.palmdoctor.mb.base.entity.SystemUser;
//import com.palmdoctor.mb.base.util.SecurityUtil;
//import com.palmdoctor.mb.server.system.service.SystemUserService;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.shiro.authc.AuthenticationInfo;
//import org.apache.shiro.authc.AuthenticationToken;
//import org.apache.shiro.authc.UsernamePasswordToken;
//import org.apache.shiro.authc.credential.HashedCredentialsMatcher;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//
//import java.util.Arrays;
//
///**
// * Shiro密码比对处理
// *
// * @author zhangnayi
// * @date 2021-03-31 18:03
// */
//@Slf4j
//@Component
//public class ShiroCredentialsMatcher extends HashedCredentialsMatcher {
//
//    @Autowired
//    private SystemUserService systemUserService;
//
//    @Override
//    public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
//        UsernamePasswordToken usernamePasswordToken = (UsernamePasswordToken) token;
//        LambdaQueryWrapper<SystemUser> queryWrapper = new LambdaQueryWrapper<>();
//        queryWrapper.eq(SystemUser::getUserName, usernamePasswordToken.getUsername())
//                .eq(SystemUser::getStatus, AuditStatusEnum2.PASS.getValue())
//                .in(SystemUser::getUserType, Arrays.asList(UserTypeEnum.ADMIN.getValue(), UserTypeEnum.BACKEND.getValue()));
//        SystemUser systemUser = systemUserService.getOne(queryWrapper);
//        if (systemUser == null) {
//            return Boolean.FALSE;
//        }
//        // 加密密码
//        String pwd = SecurityUtil.encryptPassword(new String(usernamePasswordToken.getPassword()), systemUser.getSalt());
//        // 比较密码
//        log.error("数据库 pwd={}, 用户输入pwd={}", systemUser.getPassword(), pwd);
//        return this.equals(pwd, systemUser.getPassword());
//    }
//}
